package sk.fei.vrml.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileFilter;

import sk.fei.vrml.jogl.JoglEventListener;
import sk.fei.vrml.jogl.VrmlModel;
import sk.fei.vrml.main.Constants;
import sk.fei.vrml.main.FieldException;
import sk.fei.vrml.main.Transformator;
import sk.fei.vrml.objects.ImageTextureObject;
import sk.fei.vrml.objects.PixelTextureObject;
import sk.fei.vrml.objects.SkyColor;
import sk.fei.vrml.objects.VrmlAppearance;
import sk.fei.vrml.objects.VrmlBackground;
import sk.fei.vrml.objects.VrmlCone;
import sk.fei.vrml.objects.VrmlCylinder;
import sk.fei.vrml.objects.VrmlTransform;
import sk.fei.vrml.objects.VrmlBox;
import sk.fei.vrml.objects.VrmlObject;
import sk.fei.vrml.objects.VrmlSphere;
import sk.fei.vrml.objects.VrmlViewPoint;
import sk.fei.vrml.objects.VrmlViewPointsStorage;

public class PropertiesWindow extends JPanel{
	private VrmlObject object;
	private JLabel difusalColorPreview;
	private VrmlModel vrmlModel;
	private MainFrame _window;

	//TODO upravit konstruktor s mainFramom nech mozem dat ten isty listener
	public PropertiesWindow(Object o,VrmlModel model, MainFrame window){
		//super("Properties");
		this._window=window;
		vrmlModel = model;
		this.setPreferredSize(new Dimension(180,400));
		this.setLayout(new BorderLayout());
		//this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		object = (VrmlObject)o;
		this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), object.getObjectType()));
		if (object.getObjectType() == Constants.Box) ShowPropertiesForCube();
		if (object.getObjectType() == Constants.Sphere) ShowPropertiesForSphere();
		if (object.getObjectType() == Constants.Transform) ShowPropertiesForTransformation();
		if (object.getObjectType() == Constants.Appearance) ShowPropertiesForAppearance();
		if (object.getObjectType() == Constants.Cylinder) ShowPropertiesForCylinder();
		if (object.getObjectType() == Constants.Cone) ShowPropertiesForCone();
		if (object.getObjectType() == Constants.View) ShowPropertiesForViewPoint();
		if (object.getObjectType() == Constants.Background) ShowPropertiesForBackground();
		//this.pack();
		this.setVisible(true);
	}
	
	public void ShowPropertiesForCube(){
		final VrmlBox cubeObj = (VrmlBox)object;
		JTabbedPane tabs = new JTabbedPane();
		JPanel generalPanel = new JPanel();
		JScrollPane scrollPaneForGeneral = new JScrollPane(generalPanel);
		scrollPaneForGeneral.setBorder(null);
		generalPanel.setLayout(new GridBagLayout());
		GridBagConstraints con = new GridBagConstraints();
		con.gridx = 0;
		con.gridy = 0;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel objectType = new JLabel("Type:");
		generalPanel.add(objectType,con);
		con.gridx = 1;
		con.weightx = 0;
		JLabel objectName = new JLabel(cubeObj.getObjectType());
		generalPanel.add(objectName,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		con.gridy = 1;
		con.weightx = 0;
		con.gridx = 0;
		JLabel objectWidthL = new JLabel("Width:");
		generalPanel.add(objectWidthL,con);
		final JTextField objectWidthF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		objectWidthF.setText(Float.toString(cubeObj.getX()));
		generalPanel.add(objectWidthF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel("size"),con);
		
		con.gridy = 2;
		con.gridx = 0;
		con.weightx = 0;
		JLabel objectHeightL = new JLabel("Height:");
		generalPanel.add(objectHeightL,con);
		final JTextField objectHeightF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		objectHeightF.setText(Float.toString(cubeObj.getY()));
		generalPanel.add(objectHeightF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel("size"),con);
		
		con.gridy = 3;
		con.gridx = 0;
		con.weightx = 0;
		JLabel objectDepthL = new JLabel("Depth:");
		generalPanel.add(objectDepthL,con);
		final JTextField objectDepthF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		objectDepthF.setText(Float.toString(cubeObj.getZ()));
		generalPanel.add(objectDepthF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel("size"),con);
		
		
		// Prazny element na vyplnenie spodku
		con.gridy = 4;
		con.gridx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		generalPanel.add(new JLabel(),con);
		
		tabs.addTab("General", scrollPaneForGeneral);
		

		
		JPanel aprovePanel = new JPanel();
		JButton applyBut = new JButton("Apply");
		aprovePanel.setLayout(new BorderLayout());
		aprovePanel.add(applyBut,BorderLayout.EAST);
		aprovePanel.setPreferredSize(new Dimension(400,25));
		
		applyBut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{

					cubeObj.setX(Float.valueOf(objectWidthF.getText()));
					cubeObj.setY(Float.valueOf(objectHeightF.getText()));
					cubeObj.setZ(Float.valueOf(objectDepthF.getText()));
					vrmlModel.setModelChanged();
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
			
		this.add(tabs,BorderLayout.CENTER);
		this.add(aprovePanel,BorderLayout.SOUTH);	
	}
	
	public void ShowPropertiesForTransformation(){
		final VrmlTransform transformObj = (VrmlTransform)object;
		JTabbedPane tabs = new JTabbedPane();
		JPanel generalPanel = new JPanel();
		generalPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForGeneral = new JScrollPane(generalPanel);
		scrollPaneForGeneral.setBorder(null);
		GridBagConstraints con = new GridBagConstraints();
		con.gridx = 0;
		con.gridy = 0;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel objectType = new JLabel("Type:");
		generalPanel.add(objectType,con);
		con.gridx = 1;
		con.weightx = 0;
		JLabel objectName = new JLabel(transformObj.getObjectType());
		generalPanel.add(objectName,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		con.gridy = 1;
		con.weightx = 0;
		con.gridx = 0;
		
		
		con.gridy = 3;
		con.gridx = 0;
		con.weightx = 0;
		con.gridwidth = 2;
		con.insets = new Insets(20,10,0,10);
		JLabel cordsL = new JLabel("Transformation center coordinats");
		generalPanel.add(cordsL,con);
		
		con.gridwidth = 1;
		con.insets = new Insets(10,10,0,10);
		con.gridy = 4;
		con.weightx = 0;
		con.gridx = 0;
		JLabel cordXL = new JLabel("Center Xcor:");
		generalPanel.add(cordXL,con);
		final JTextField objectcordXF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		objectcordXF.setText(Float.toString(transformObj.getScaleCenterX()));
		generalPanel.add(objectcordXF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 5;
		con.gridx = 0;
		con.weightx = 0;
		JLabel cordYL = new JLabel("Center Ycor:");
		generalPanel.add(cordYL,con);
		final JTextField objectcordYF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		objectcordYF.setText(Float.toString(transformObj.getScaleCenterY()));
		generalPanel.add(objectcordYF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 6;
		con.gridx = 0;
		con.weightx = 0;
		JLabel cordZL = new JLabel("Center Zcor:");
		generalPanel.add(cordZL,con);
		final JTextField objectcordZF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		objectcordZF.setText(Float.toString(transformObj.getScaleCenterZ()));
		generalPanel.add(objectcordZF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		// Prazny element na vyplnenie spodku
		con.gridy = 7;
		con.gridx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		generalPanel.add(new JLabel(),con);
		
		tabs.addTab("General", scrollPaneForGeneral);
		/*
		 * Tab s nastavenim rotacie
		 */
		JPanel rotationPanel = new JPanel();
		rotationPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForRotation = new JScrollPane(rotationPanel);
		scrollPaneForRotation.setBorder(null);
		con.weightx = 0;
		con.weighty = 0;
		con.gridwidth = 1;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.gridy = 0;
		con.gridx = 0;
		JLabel rotXL = new JLabel("Rotation X:");
		rotationPanel.add(rotXL,con);
		final JTextField rotXF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0.15;
		rotXF.setText(Float.toString(transformObj.getRotationX()));
		rotationPanel.add(rotXF,con);
		con.gridx = 2;
		con.weightx = 1;
		rotationPanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 1;
		con.gridx = 0;
		JLabel rotYL = new JLabel("Rotation Y:");
		rotationPanel.add(rotYL,con);
		final JTextField rotYF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		rotYF.setText(Float.toString(transformObj.getRotationY()));
		rotationPanel.add(rotYF,con);
		con.gridx = 2;
		con.weightx = 1;
		rotationPanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 2;
		con.gridx = 0;
		JLabel rotZL = new JLabel("Rotation Z:");
		rotationPanel.add(rotZL,con);
		final JTextField rotZF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		rotZF.setText(Float.toString(transformObj.getRotationZ()));
		rotationPanel.add(rotZF,con);
		con.gridx = 2;
		con.weightx = 1;
		rotationPanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 3;
		con.gridx = 0;
		JLabel rotAngleL = new JLabel("Rotation angle:");
		rotationPanel.add(rotAngleL,con);
		final JTextField rotAngleF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		rotAngleF.setText(Float.toString(transformObj.getRotationAngle()));
		rotationPanel.add(rotAngleF,con);
		con.gridx = 2;
		con.weightx = 1;
		rotationPanel.add(new JLabel(""),con);
		// Prazny element na vyplnenie spodku
		con.gridy = 4;
		con.gridx = 0;
		con.weightx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		rotationPanel.add(new JLabel(),con);
		
		tabs.addTab("Rotation", scrollPaneForRotation);
		
		/*
		 * Tab s nastavenim posunu
		 */
		JPanel translationPanel = new JPanel();
		translationPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForTranslation = new JScrollPane(translationPanel);
		scrollPaneForTranslation.setBorder(null);
		con.weightx = 0;
		con.weighty = 0;
		con.gridwidth = 1;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.gridy = 0;
		con.gridx = 0;
		JLabel transXL = new JLabel("Translation X:");
		translationPanel.add(transXL,con);
		final JTextField transXF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0.15;
		transXF.setText(Float.toString(transformObj.getTranslationX()));
		translationPanel.add(transXF,con);
		con.gridx = 2;
		con.weightx = 1;
		translationPanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 1;
		con.gridx = 0;
		JLabel transYL = new JLabel("Translation Y:");
		translationPanel.add(transYL,con);
		final JTextField transYF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		transYF.setText(Float.toString(transformObj.getTranslationY()));
		translationPanel.add(transYF,con);
		con.gridx = 2;
		con.weightx = 1;
		translationPanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 2;
		con.gridx = 0;
		JLabel transZL = new JLabel("Translatino Z:");
		translationPanel.add(transZL,con);
		final JTextField transZF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		transZF.setText(Float.toString(transformObj.getTranslationZ()));
		translationPanel.add(transZF,con);
		con.gridx = 2;
		con.weightx = 1;
		translationPanel.add(new JLabel(""),con);
		
		// Prazny element na vyplnenie spodku
		con.gridy = 3;
		con.gridx = 0;
		con.weightx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		translationPanel.add(new JLabel(),con);
		
		tabs.addTab("Translation", scrollPaneForTranslation);
		
		/*
		 * Tab s nastavenim scale
		 */
		JPanel scalePanel = new JPanel();
		scalePanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForScale = new JScrollPane(scalePanel);
		scrollPaneForScale.setBorder(null);
		con.weightx = 0;
		con.weighty = 0;
		con.gridwidth = 1;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.gridy = 0;
		con.gridx = 0;
		JLabel scaleXL = new JLabel("Scale X:");
		scalePanel.add(scaleXL,con);
		final JTextField scaleXF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0.15;
		scaleXF.setText(Float.toString(transformObj.getScaleX()));
		scalePanel.add(scaleXF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 1;
		con.gridx = 0;
		JLabel scaleYL = new JLabel("Scale Y:");
		scalePanel.add(scaleYL,con);
		final JTextField scaleYF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleYF.setText(Float.toString(transformObj.getScaleY()));
		scalePanel.add(scaleYF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 2;
		con.gridx = 0;
		JLabel scaleZL = new JLabel("Scale Z:");
		scalePanel.add(scaleZL,con);
		final JTextField scaleZF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleZF.setText(Float.toString(transformObj.getScaleZ()));
		scalePanel.add(scaleZF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		
		con.insets = new Insets(30,10,0,10);
		con.weightx = 0;
		con.gridy = 3;
		con.gridx = 0;
		JLabel scaleOrientationXL = new JLabel("Scale orientation X:");
		scalePanel.add(scaleOrientationXL,con);
		final JTextField scaleOrientationXF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleOrientationXF.setText(Float.toString(transformObj.getScaleOrientationX()));
		scalePanel.add(scaleOrientationXF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		con.gridy = 4;
		con.gridx = 0;
		JLabel scaleOrientationYL = new JLabel("Scale orientation Y:");
		scalePanel.add(scaleOrientationYL,con);
		final JTextField scaleOrientationYF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleOrientationYF.setText(Float.toString(transformObj.getScaleOrientationY()));
		scalePanel.add(scaleOrientationYF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 5;
		con.gridx = 0;
		JLabel scaleOrientationZL = new JLabel("Scale orientation Z:");
		scalePanel.add(scaleOrientationZL,con);
		final JTextField scaleOrientationZF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleOrientationZF.setText(Float.toString(transformObj.getScaleOrientationZ()));
		scalePanel.add(scaleOrientationZF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 6;
		con.gridx = 0;
		JLabel scaleOrientationDeg = new JLabel("Scale orientation degree:");
		scalePanel.add(scaleOrientationDeg,con);
		final JTextField scaleOrientationDegF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleOrientationDegF.setText(Float.toString(transformObj.getScaleOrientationDeg()));
		scalePanel.add(scaleOrientationDegF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		/*
		con.insets = new Insets(30,10,0,10);
		con.weightx = 0;
		con.gridy = 7;
		con.gridx = 0;
		JLabel scaleCenterXL = new JLabel("Scale center X:");
		scalePanel.add(scaleCenterXL,con);
		final JTextField scaleCenterXF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleCenterXF.setText(Float.toString(transformObj.getScaleCenterX()));
		scalePanel.add(scaleCenterXF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		con.gridy = 8;
		con.gridx = 0;
		JLabel scaleCenterYL = new JLabel("Scale center Y:");
		scalePanel.add(scaleCenterYL,con);
		final JTextField scaleCenterYF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleCenterYF.setText(Float.toString(transformObj.getScaleCenterY()));
		scalePanel.add(scaleCenterYF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);
		con.weightx = 0;
		con.gridy = 9;
		con.gridx = 0;
		JLabel scaleCenterZL = new JLabel("Scale center Z:");
		scalePanel.add(scaleCenterZL,con);
		final JTextField scaleCenterZF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		scaleCenterZF.setText(Float.toString(transformObj.getScaleCenterZ()));
		scalePanel.add(scaleCenterZF,con);
		con.gridx = 2;
		con.weightx = 1;
		scalePanel.add(new JLabel(""),con);*/
		// Prazny element na vyplnenie spodku
		con.gridy = 7;
		con.gridx = 0;
		con.weightx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		scalePanel.add(new JLabel(),con);
		
		
		tabs.addTab("Scaling", scrollPaneForScale);
		
		
		JPanel aprovePanel = new JPanel();
		JButton applyBut = new JButton("Apply");
		aprovePanel.setLayout(new BorderLayout());
		aprovePanel.add(applyBut,BorderLayout.EAST);
		aprovePanel.setPreferredSize(new Dimension(400,25));
		
		applyBut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					transformObj.setRotationX(Float.valueOf(rotXF.getText()));
					transformObj.setRotationY(Float.valueOf(rotYF.getText()));
					transformObj.setRotationZ(Float.valueOf(rotZF.getText()));
					transformObj.setRotationAngle(Float.valueOf(rotAngleF.getText()));
					transformObj.setTranslationX(Float.valueOf(transXF.getText()));
					transformObj.setTranslationY(Float.valueOf(transYF.getText()));
					transformObj.setTranslationZ(Float.valueOf(transZF.getText()));
					transformObj.setScaleX(Float.valueOf(scaleXF.getText()));
					transformObj.setScaleY(Float.valueOf(scaleYF.getText()));
					transformObj.setScaleZ(Float.valueOf(scaleZF.getText()));
					transformObj.setScaleOrientationX(Float.valueOf(scaleOrientationXF.getText()));
					transformObj.setScaleOrientationY(Float.valueOf(scaleOrientationYF.getText()));
					transformObj.setScaleOrientationZ(Float.valueOf(scaleOrientationZF.getText()));
					transformObj.setScaleOrientationDeg(Float.valueOf(scaleOrientationDegF.getText()));
					transformObj.setScaleCenterX(Float.valueOf(objectcordXF.getText()));
					transformObj.setScaleCenterY(Float.valueOf(objectcordYF.getText()));
					transformObj.setScaleCenterZ(Float.valueOf(objectcordZF.getText()));
					vrmlModel.setModelChanged();
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
			
		this.add(tabs,BorderLayout.CENTER);
		this.add(aprovePanel,BorderLayout.SOUTH);	
	}
	
	public void ShowPropertiesForSphere(){
		final VrmlSphere sphereObj = (VrmlSphere)object;
		JTabbedPane tabs = new JTabbedPane();
		JPanel generalPanel = new JPanel();
		generalPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForGeneral = new JScrollPane(generalPanel);
		scrollPaneForGeneral.setBorder(null);
		GridBagConstraints con = new GridBagConstraints();
		con.gridx = 0;
		con.gridy = 0;
		con.weighty = 0;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel objectType = new JLabel("Type:");
		generalPanel.add(objectType,con);
		con.gridx = 1;
		con.weightx = 0;
		JLabel objectName = new JLabel(sphereObj.getObjectType());
		generalPanel.add(objectName,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);

		
		con.gridy = 1;
		con.gridx = 0;
		con.weightx = 0;
		con.gridwidth = 1;
		con.insets = new Insets(20,10,0,10);
		JLabel radiusL = new JLabel("Sphere radius:");
		generalPanel.add(radiusL,con);
		final JTextField sphereRadiusF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		sphereRadiusF.setText(Float.toString(sphereObj.getRadius()));
		generalPanel.add(sphereRadiusF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		
		
		// Prazny element na vyplnenie spodku
		con.gridy = 2;
		con.gridx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		generalPanel.add(new JLabel(),con);
		
		tabs.addTab("General", scrollPaneForGeneral);
	
		
		JPanel aprovePanel = new JPanel();
		JButton applyBut = new JButton("Apply");
		aprovePanel.setLayout(new BorderLayout());
		aprovePanel.add(applyBut,BorderLayout.EAST);
		aprovePanel.setPreferredSize(new Dimension(400,25));
		
		applyBut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					sphereObj.setRadius(Float.valueOf(sphereRadiusF.getText()));
					vrmlModel.setModelChanged();
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
			
		this.add(tabs,BorderLayout.CENTER);
		this.add(aprovePanel,BorderLayout.SOUTH);	
	}
	
	public void ShowPropertiesForAppearance(){
		final VrmlAppearance appearanceObj = (VrmlAppearance)object;
		JTabbedPane tabs = new JTabbedPane();
		JPanel generalPanel = new JPanel();
		generalPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForGeneral = new JScrollPane(generalPanel);
		scrollPaneForGeneral.setBorder(null);
		GridBagConstraints con = new GridBagConstraints();
		con.gridx = 0;
		con.gridy = 0;
		con.weighty = 0;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel colorsL = new JLabel("Material colors");
		generalPanel.add(colorsL,con);
		
		// difuse color
		con.gridx = 0;
		con.gridy = 1;
		con.weighty = 0;
		JLabel difuseCL = new JLabel("Diffuse color:");
		generalPanel.add(difuseCL,con);
		con.gridx = 1;
		difusalColorPreview = new JLabel("        ");
		difusalColorPreview.setOpaque(true);
		float[] colors = appearanceObj.getMaterial().getDiffuseColor();
		Color difusalColor = new Color(colors[0],colors[1],colors[2]);
		difusalColorPreview.setBackground(difusalColor);
		generalPanel.add(difusalColorPreview,con);
		con.gridx = 2;
		JButton selectColorButton = new JButton("Pick color");
		selectColorButton.addActionListener(new ColorPickerListener(difusalColor,difusalColorPreview));
		generalPanel.add(selectColorButton,con);
		con.gridx = 3;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		// ambient intesity
		con.gridx = 0;
		con.gridy = 2;
		con.weightx = 0;
		JLabel ambientIL = new JLabel("Ambient intesity:");
		generalPanel.add(ambientIL,con);
		final JTextField ambientIF = new JTextField(); 
		con.gridx = 1;
		ambientIF.setText(Float.toString(appearanceObj.getMaterial().getAmbientIntensity()));
		generalPanel.add(ambientIF,con);
		
		//emissive color
		con.gridx = 0;
		con.gridy = 3;
		JLabel emissiveCL = new JLabel("Emissive color:");
		generalPanel.add(emissiveCL,con);
		con.gridx = 1;
		final JLabel emissiveColorPreview = new JLabel("        ");
		emissiveColorPreview.setOpaque(true);
		float[] ecolors = appearanceObj.getMaterial().getEmissiveColor();
		Color emissiveColor = new Color(ecolors[0],ecolors[1],ecolors[2],ecolors[3]);
		emissiveColorPreview.setBackground(emissiveColor);
		generalPanel.add(emissiveColorPreview,con);
		con.gridx = 2;
		JButton selectColorButton2 = new JButton("Pick color");
		selectColorButton2.addActionListener(new ColorPickerListener(emissiveColor,emissiveColorPreview));
		generalPanel.add(selectColorButton2,con);
		con.gridx = 3;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		//specular color
		con.gridx = 0;
		con.gridy = 4;
		JLabel specularCL = new JLabel("Specular color:");
		generalPanel.add(specularCL,con);
		con.gridx = 1;
		final JLabel specularColorPreview = new JLabel("        ");
		specularColorPreview.setOpaque(true);
		float[] scolors = appearanceObj.getMaterial().getSpecularColor();
		Color specularColor = new Color(scolors[0],scolors[1],scolors[2]);
		specularColorPreview.setBackground(specularColor);
		generalPanel.add(specularColorPreview,con);
		con.gridx = 2;
		JButton selectColorButton3 = new JButton("Pick color");
		selectColorButton3.addActionListener(new ColorPickerListener(specularColor,specularColorPreview));
		generalPanel.add(selectColorButton3,con);
		con.gridx = 3;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		//shininess
		con.gridx = 0;
		con.gridy = 5;
		con.weightx = 0;
		JLabel shinessIL = new JLabel("Shininess:");
		generalPanel.add(shinessIL,con);
		final JTextField shinessIF = new JTextField(); 
		con.gridx = 1;
		shinessIF.setText(Float.toString(appearanceObj.getMaterial().getShininess()));
		generalPanel.add(shinessIF,con);
		
		//transparency
		con.gridx = 0;
		con.gridy = 6;
		con.weightx = 0;
		JLabel transparentIL = new JLabel("Transparency:");
		generalPanel.add(transparentIL,con);
		final JTextField transparenIF = new JTextField(); 
		con.gridx = 1;
		transparenIF.setText(Float.toString(appearanceObj.getMaterial().getTransparency()));
		generalPanel.add(transparenIF,con);
		
		// meno materialu
		con.gridx = 0;
		con.gridy = 7;
		con.gridwidth = 2;
		con.weighty = 0;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel materialNameL = new JLabel("Material name:");
		generalPanel.add(materialNameL,con);
		final JTextField materialNameF = new JTextField(); 
		con.gridx = 1;
		if (appearanceObj.getMaterial().getName() == null) materialNameF.setText("not defined");
		else materialNameF.setText(appearanceObj.getMaterial().getName());
		generalPanel.add(materialNameF,con);
		
		// Prazny element na vyplnenie spodku
		con.gridy = 8;
		con.gridx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		generalPanel.add(new JLabel(),con);
		
		tabs.addTab("General", scrollPaneForGeneral);
	
		/*
		 * Tab s nastavenim textruy
		 */
		JPanel texturePanel = new JPanel();
		texturePanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForTexture = new JScrollPane(texturePanel);
		scrollPaneForTexture.setBorder(null);
		
		con.weightx = 0;
		con.weighty = 0;
		con.gridwidth = 1;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.gridy = 0;
		con.gridx = 0;
		final JRadioButton nonTextureButton = new JRadioButton("No texture");
		if (appearanceObj.getTexture() == null) nonTextureButton.setSelected(true);
		texturePanel.add(nonTextureButton,con);
		con.gridy = 1;
		con.gridx = 0;
		con.insets = new Insets(30,10,0,10);
		final JRadioButton imageTextureButton = new JRadioButton("Image texture");
		if (appearanceObj.getTexture() != null && appearanceObj.getTexture().getTextureType()==Constants.ImageTexture) imageTextureButton.setSelected(true);
		texturePanel.add(imageTextureButton,con);
		
		con.weightx = 0;
		con.weighty = 0;
		con.gridwidth = 1;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.gridy = 2;
		con.gridx = 0;
		JLabel textureUrlL = new JLabel("Texture URL:");
		texturePanel.add(textureUrlL,con);
		final JTextField textureUrlF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		con.gridwidth = 2;
		textureUrlF.setEditable(false);
		textureUrlF.setText("");
		texturePanel.add(textureUrlF,con);
		con.gridwidth = 1;
		con.gridx = 3;
		JButton urlButton = new JButton("Open");
		urlButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ev) {
				 JFileChooser chooser = new JFileChooser();
				 //chooser.removeChoosableFileFilter( chooser.getFileFilter() );
				 chooser.setAcceptAllFileFilterUsed(false);
				 chooser.setFileFilter(new FileFilter() {
						@Override
						public String getDescription() {
							return "*.png .jpg. .gif";
						}
						@Override
						public boolean accept(File arg0) {
							if (arg0.isDirectory()) return true;
							String[] fileNameArray = arg0.getAbsolutePath().split("[.]");
							if (fileNameArray.length > 1
									&& (fileNameArray[fileNameArray.length - 1]
											.compareTo("png") == 0 || fileNameArray[fileNameArray.length - 1]
													.compareTo("jpg") == 0 || fileNameArray[fileNameArray.length - 1].compareTo("gif") == 0)) {
								return true;
							} else {
								return false;
							}
						}
					});
				    int returnVal = chooser.showOpenDialog((JButton)ev.getSource());
				    if(returnVal == JFileChooser.APPROVE_OPTION) {
				    	textureUrlF.setText(chooser.getSelectedFile().getAbsolutePath());
				    }
			}
		});
		texturePanel.add(urlButton,con);
		
		con.gridy = 3;
		con.gridx = 0;
		con.weightx = 0;
		JLabel repeatSL = new JLabel("RepeatS");
		texturePanel.add(repeatSL,con);
		Boolean[] values = {new Boolean(true),new Boolean(false)};
		final JComboBox booleanBoxRepeatSL= new JComboBox(values); 
		con.gridx = 1;
		con.weightx = 0;
		if (appearanceObj.getTexture() == null || appearanceObj.getTexture().getTextureType()!=Constants.ImageTexture) booleanBoxRepeatSL.setSelectedItem(false);
		else booleanBoxRepeatSL.setSelectedItem(((ImageTextureObject)appearanceObj.getTexture()).isRepeatS());
		texturePanel.add(booleanBoxRepeatSL,con);
		con.gridx = 2;
		con.weightx = 1;
		texturePanel.add(new JLabel(),con);
		con.gridy = 4;
		con.gridx = 0;
		con.weightx = 0;
		JLabel repeatTL = new JLabel("RepeatT");
		texturePanel.add(repeatTL,con);
		final JComboBox booleanBoxRepeatTL= new JComboBox(values); 
		con.gridx = 1;
		con.weightx = 0;
		if (appearanceObj.getTexture() == null || appearanceObj.getTexture().getTextureType()!=Constants.ImageTexture) booleanBoxRepeatTL.setSelectedItem(false);
		else booleanBoxRepeatTL.setSelectedItem(((ImageTextureObject)appearanceObj.getTexture()).isRepeatT());
		texturePanel.add(booleanBoxRepeatTL,con);
		con.gridx = 2;
		con.weightx = 1;
		texturePanel.add(new JLabel(),con);
		
		con.gridy = 5;
		con.gridx = 0;
		con.weightx = 0;
		con.insets = new Insets(30,10,0,10);
		final JRadioButton pixelTextureButton = new JRadioButton("Pixel texture");
		if (appearanceObj.getTexture() != null && appearanceObj.getTexture().getTextureType()==Constants.PixelTexture) pixelTextureButton.setSelected(true);
		texturePanel.add(pixelTextureButton,con);
		
		con.insets = new Insets(10,10,0,10);
		con.gridy = 6;
		con.gridx = 0;
		JLabel pixelWidthL = new JLabel("Texture width:");
		texturePanel.add(pixelWidthL,con);
		final JTextField pixelWidthF = new JTextField();
		if (appearanceObj.getTexture() == null || appearanceObj.getTexture().getTextureType()!=Constants.PixelTexture) ;
		else {
			pixelWidthF.setText(String.valueOf((((PixelTextureObject)appearanceObj.getTexture()).getTextureWidth())));
		}
		con.gridx = 1;
		texturePanel.add(pixelWidthF,con);
	
		
		con.gridy = 7;
		con.gridx = 0;
		JLabel pixelHeightL = new JLabel("Texture height:");
		texturePanel.add(pixelHeightL,con);
		final JTextField pixelHeightF = new JTextField();
		if (appearanceObj.getTexture() == null || appearanceObj.getTexture().getTextureType()!=Constants.PixelTexture) ;
		else {
			pixelHeightF.setText(String.valueOf((((PixelTextureObject)appearanceObj.getTexture()).getTextureHeight())));
		}
		con.gridx = 1;
		texturePanel.add(pixelHeightF,con);
		
		con.gridy = 8;
		con.gridx = 0;
		JLabel pixelDepthL = new JLabel("Pixel format:");
		texturePanel.add(pixelDepthL,con);
		Integer[] intvalues = {1,2,3,4};
		final JComboBox formatBoxL= new JComboBox(intvalues); 
		if (appearanceObj.getTexture() == null || appearanceObj.getTexture().getTextureType()!=Constants.PixelTexture) ;
		else {
			formatBoxL.setSelectedItem(Integer.valueOf((((PixelTextureObject)appearanceObj.getTexture()).getTextureFormat())));
		}
		con.gridx = 1;
		con.weightx = 0;
		texturePanel.add(formatBoxL,con);
		
		con.gridy = 9;
		con.gridx = 0;
		con.weightx = 0;
		JLabel repeatPSL = new JLabel("RepeatS");
		texturePanel.add(repeatPSL,con);
		final JComboBox booleanBoxRepeatPSL= new JComboBox(values); 
		if (appearanceObj.getTexture() == null || appearanceObj.getTexture().getTextureType()!=Constants.PixelTexture) booleanBoxRepeatPSL.setSelectedItem(false);
		else booleanBoxRepeatPSL.setSelectedItem(((PixelTextureObject)appearanceObj.getTexture()).isRepeatT());
		con.gridx = 1;
		con.weightx = 0;
		texturePanel.add(booleanBoxRepeatPSL,con);
		con.gridx = 2;
		con.weightx = 1;
		texturePanel.add(new JLabel(),con);
		con.gridy = 10;
		con.gridx = 0;
		con.weightx = 0;
		JLabel repeatPTL = new JLabel("RepeatT");
		texturePanel.add(repeatPTL,con);
		final JComboBox booleanBoxRepeatPTL= new JComboBox(values); 
		if (appearanceObj.getTexture() == null || appearanceObj.getTexture().getTextureType()!=Constants.PixelTexture) booleanBoxRepeatPTL.setSelectedItem(false);
		else booleanBoxRepeatPTL.setSelectedItem(((PixelTextureObject)appearanceObj.getTexture()).isRepeatT());
		con.gridx = 1;
		con.weightx = 0;
		texturePanel.add(booleanBoxRepeatPTL,con);
		con.gridx = 2;
		con.weightx = 1;
		texturePanel.add(new JLabel(),con);
		
		con.gridy = 11;
		con.gridx = 0;
		JLabel pixelsL = new JLabel("Color values:");
		texturePanel.add(pixelsL,con);
		final JTextField pixelsF = new JTextField();
		pixelsF.setToolTipText("Use signed byte values from range -124 to 124. Put one space between numbers. \nExample: for width=2, height=2 and format=1(Luminance) string should look like:-120 -80 50 50");
		if (appearanceObj.getTexture() == null || appearanceObj.getTexture().getTextureType()!=Constants.PixelTexture) ;
		else {
			String tmp = Arrays.toString((((PixelTextureObject)appearanceObj.getTexture()).getTextureBytes())).replace(", ", " ");
			pixelsF.setText(tmp.substring(1, tmp.length()-2));
		}
		con.gridx = 1;
		con.gridwidth = 3;
		texturePanel.add(pixelsF,con);
		
		// Prazny element na vyplnenie spodku
		con.gridy = 12;
		con.gridx = 0;
		con.gridwidth = 4;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		texturePanel.add(new JLabel(),con);
		
		ButtonGroup group = new ButtonGroup();
		group.add(nonTextureButton);
		group.add(imageTextureButton);
		group.add(pixelTextureButton);
				
		tabs.addTab("Texture", scrollPaneForTexture);
		
		
		JPanel aprovePanel = new JPanel();
		JButton applyBut = new JButton("Apply");
		aprovePanel.setLayout(new BorderLayout());
		aprovePanel.add(applyBut,BorderLayout.EAST);
		aprovePanel.setPreferredSize(new Dimension(400,25));
		
		applyBut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					float[] comp = new float[4];
					comp[3]=Float.valueOf(transparenIF.getText());
					comp[3] = (float)1.0 - comp[3];
					if (comp[3]<0) comp[3] = 0;
					if (comp[3]>1) comp[3] = 1;
					appearanceObj.getMaterial().setDiffuseColor(difusalColorPreview.getBackground().getRGBColorComponents(comp));
					appearanceObj.getMaterial().setAmbientIntensity(Float.valueOf(ambientIF.getText()));
					appearanceObj.getMaterial().setEmissiveColor(emissiveColorPreview.getBackground().getColorComponents(comp));
					appearanceObj.getMaterial().setSpecularColor(specularColorPreview.getBackground().getColorComponents(comp));
					appearanceObj.getMaterial().setShininess(Float.valueOf(shinessIF.getText()));
					appearanceObj.getMaterial().setTransparency(comp[3]);
					if (!materialNameF.getText().contentEquals("not defined"))appearanceObj.getMaterial().setName(materialNameF.getText());
					if (nonTextureButton.isSelected()){
						appearanceObj.setTexture(null);
						return;
					}
					else if (imageTextureButton.isSelected()){
						if (textureUrlF.getText().isEmpty()) return;
						File file=new File(textureUrlF.getText());
						ImageTextureObject texture = new ImageTextureObject();
						texture.setTextureUrl(new URL("file", "", textureUrlF.getText()));
						texture.setRepeatS((Boolean)booleanBoxRepeatSL.getSelectedItem());
						texture.setRepeatT((Boolean)booleanBoxRepeatTL.getSelectedItem());
						appearanceObj.setImageTexture(texture);
					}else if (pixelTextureButton.isSelected()){
						pixelsF.getText();
						byte[] bytes = convertStringArraytoByteArray(pixelsF.getText().split(" "));
						appearanceObj.setPixelTexture(Integer.valueOf(pixelWidthF.getText()), Integer.valueOf(pixelHeightF.getText()), (Integer)formatBoxL.getSelectedItem(), (Boolean)booleanBoxRepeatPSL.getSelectedItem(), (Boolean)booleanBoxRepeatPTL.getSelectedItem(), bytes);
					}
					//appearanceObj.setPixelTexture();
				}catch(FieldException e){
					JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					e.printStackTrace();
					return;
				}
			}
		});
			
		this.add(tabs,BorderLayout.CENTER);
		this.add(aprovePanel,BorderLayout.SOUTH);	
	}
	
	public void ShowPropertiesForCylinder(){
		final VrmlCylinder cylinderObj = (VrmlCylinder)object;
		JTabbedPane tabs = new JTabbedPane();
		JPanel generalPanel = new JPanel();
		generalPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForGeneral = new JScrollPane(generalPanel);
		scrollPaneForGeneral.setBorder(null);
		GridBagConstraints con = new GridBagConstraints();
		con.gridx = 0;
		con.gridy = 0;
		con.weighty = 0;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel objectType = new JLabel("Type:");
		generalPanel.add(objectType,con);
		con.gridx = 1;
		con.weightx = 0;
		JLabel objectName = new JLabel(cylinderObj.getObjectType());
		generalPanel.add(objectName,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);

		
		con.gridy = 1;
		con.gridx = 0;
		con.weightx = 0;
		con.gridwidth = 1;
		con.insets = new Insets(10,10,0,10);
		JLabel radiusL = new JLabel("Cylinder radius");
		generalPanel.add(radiusL,con);
		final JTextField cylinderRadiusF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		cylinderRadiusF.setText(Float.toString(cylinderObj.getRadius()));
		generalPanel.add(cylinderRadiusF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 2;
		con.gridx = 0;
		con.weightx = 0;
		JLabel heightL = new JLabel("Cylinder height");
		generalPanel.add(heightL,con);
		final JTextField cylinderHeightF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		cylinderHeightF.setText(Float.toString(cylinderObj.getHeight()));
		generalPanel.add(cylinderHeightF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 3;
		con.gridx = 0;
		con.weightx = 0;
		JLabel sideL = new JLabel("Show side");
		generalPanel.add(sideL,con);
		Boolean[] values = {new Boolean(true),new Boolean(false)};
		final JComboBox booleanBoxSide = new JComboBox(values); 
		con.gridx = 1;
		con.weightx = 0;
		booleanBoxSide.setSelectedItem(cylinderObj.getSide());
		generalPanel.add(booleanBoxSide,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 4;
		con.gridx = 0;
		con.weightx = 0;
		JLabel bottomL = new JLabel("Show bottom");
		generalPanel.add(bottomL,con);
		final JComboBox booleanBoxBottom = new JComboBox(values); 
		con.gridx = 1;
		con.weightx = 0;
		booleanBoxBottom.setSelectedItem(cylinderObj.getBottom());
		generalPanel.add(booleanBoxBottom,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 5;
		con.gridx = 0;
		con.weightx = 0;
		JLabel topL = new JLabel("Show top");
		generalPanel.add(topL,con);
		final JComboBox booleanBoxTop = new JComboBox(values); 
		con.gridx = 1;
		con.weightx = 0;
		booleanBoxTop.setSelectedItem(cylinderObj.getTop());
		generalPanel.add(booleanBoxTop,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		
		// Prazny element na vyplnenie spodku
		con.gridy = 6;
		con.gridx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		generalPanel.add(new JLabel(),con);
		
		tabs.addTab("General", scrollPaneForGeneral);
	
		
		JPanel aprovePanel = new JPanel();
		JButton applyBut = new JButton("Apply");
		aprovePanel.setLayout(new BorderLayout());
		aprovePanel.add(applyBut,BorderLayout.EAST);
		aprovePanel.setPreferredSize(new Dimension(400,25));
		
		applyBut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					cylinderObj.setRadius(Float.valueOf(cylinderRadiusF.getText()));
					cylinderObj.setHeight(Float.valueOf(cylinderHeightF.getText()));
					cylinderObj.setSide((Boolean)booleanBoxSide.getSelectedItem());
					cylinderObj.setBottom((Boolean)booleanBoxBottom.getSelectedItem());
					cylinderObj.setTop((Boolean)booleanBoxTop.getSelectedItem());
					vrmlModel.setModelChanged();
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
			
		this.add(tabs,BorderLayout.CENTER);
		this.add(aprovePanel,BorderLayout.SOUTH);	
	}
	
	public void ShowPropertiesForCone(){
		final VrmlCone coneObj = (VrmlCone)object;
		JTabbedPane tabs = new JTabbedPane();
		JPanel generalPanel = new JPanel();
		generalPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForGeneral = new JScrollPane(generalPanel);
		scrollPaneForGeneral.setBorder(null);
		GridBagConstraints con = new GridBagConstraints();
		con.gridx = 0;
		con.gridy = 0;
		con.weighty = 0;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel objectType = new JLabel("Type:");
		generalPanel.add(objectType,con);
		con.gridx = 1;
		con.weightx = 0;
		JLabel objectName = new JLabel(coneObj.getObjectType());
		generalPanel.add(objectName,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);

		
		con.gridy = 1;
		con.gridx = 0;
		con.weightx = 0;
		con.gridwidth = 1;
		con.insets = new Insets(20,10,0,10);
		JLabel radiusL = new JLabel("Bottom radius");
		generalPanel.add(radiusL,con);
		final JTextField coneRadiusF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		coneRadiusF.setText(Float.toString(coneObj.getBottomRadius()));
		generalPanel.add(coneRadiusF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 2;
		con.gridx = 0;
		con.weightx = 0;
		con.insets = new Insets(20,10,0,10);
		JLabel heightL = new JLabel("Cone height");
		generalPanel.add(heightL,con);
		final JTextField coneHeightF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		coneHeightF.setText(Float.toString(coneObj.getHeight()));
		generalPanel.add(coneHeightF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 3;
		con.gridx = 0;
		con.weightx = 0;
		con.insets = new Insets(20,10,0,10);
		JLabel sideL = new JLabel("Show side");
		generalPanel.add(sideL,con);
		Boolean[] values = {new Boolean(true),new Boolean(false)};
		final JComboBox booleanBoxSide = new JComboBox(values); 
		con.gridx = 1;
		con.weightx = 0;
		booleanBoxSide.setSelectedItem(coneObj.getSide());
		generalPanel.add(booleanBoxSide,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.gridy = 4;
		con.gridx = 0;
		con.weightx = 0;
		con.insets = new Insets(20,10,0,10);
		JLabel bottomL = new JLabel("Show bottom");
		generalPanel.add(bottomL,con);
		final JComboBox booleanBoxBottom = new JComboBox(values); 
		con.gridx = 1;
		con.weightx = 0;
		booleanBoxBottom.setSelectedItem(coneObj.getBottom());
		generalPanel.add(booleanBoxBottom,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		
		// Prazny element na vyplnenie spodku
		con.gridy = 5;
		con.gridx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		generalPanel.add(new JLabel(),con);
		
		tabs.addTab("General", scrollPaneForGeneral);
	
		
		JPanel aprovePanel = new JPanel();
		JButton applyBut = new JButton("Apply");
		aprovePanel.setLayout(new BorderLayout());
		aprovePanel.add(applyBut,BorderLayout.EAST);
		aprovePanel.setPreferredSize(new Dimension(400,25));
		
		applyBut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					coneObj.setBottomRadius(Float.valueOf(coneRadiusF.getText()));
					coneObj.setHeight(Float.valueOf(coneHeightF.getText()));
					coneObj.setSide((Boolean)booleanBoxSide.getSelectedItem());
					coneObj.setBottom((Boolean)booleanBoxBottom.getSelectedItem());
					vrmlModel.setModelChanged();
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
			
		this.add(tabs,BorderLayout.CENTER);
		this.add(aprovePanel,BorderLayout.SOUTH);	
	}
	
	public void ShowPropertiesForViewPoint(){
		final VrmlViewPoint viewObj = (VrmlViewPoint)object;
		JTabbedPane tabs = new JTabbedPane();
		JPanel generalPanel = new JPanel();
		generalPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForGeneral = new JScrollPane(generalPanel);
		scrollPaneForGeneral.setBorder(null);
		GridBagConstraints con = new GridBagConstraints();
		con.gridx = 0;
		con.gridy = 0;
		con.weighty = 0;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel objectType = new JLabel("Type:");
		generalPanel.add(objectType,con);
		con.gridx = 1;
		con.weightx = 0;
		JLabel objectName = new JLabel(viewObj.getObjectType());
		generalPanel.add(objectName,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.weightx = 0;
		con.weighty = 0;
		con.gridwidth = 1;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.gridy = 1;
		con.gridx = 0;
		
		//Translations
		JLabel trans = new JLabel("Translations:");
		generalPanel.add(trans,con);
		con.gridy = 2;
		JLabel transXL = new JLabel("Translation X:");
		generalPanel.add(transXL,con);
		final JTextField transXF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0.15;
		transXF.setText(Float.toString(viewObj.getPositionX()));
		generalPanel.add(transXF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		con.weightx = 0;
		con.gridy = 3;
		con.gridx = 0;
		JLabel transYL = new JLabel("Translation Y:");
		generalPanel.add(transYL,con);
		final JTextField transYF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		transYF.setText(Float.toString(viewObj.getPositionY()));
		generalPanel.add(transYF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		con.weightx = 0;
		con.gridy = 4;
		con.gridx = 0;
		JLabel transZL = new JLabel("Translation Z:");
		generalPanel.add(transZL,con);
		final JTextField transZF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		transZF.setText(Float.toString(viewObj.getPositionZ()));
		generalPanel.add(transZF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		//Rotations
		con.weightx = 0;
		con.gridy = 5;
		generalPanel.add(new JLabel(),con);
		con.gridx = 0;
		con.gridy = 6;
		JLabel rot = new JLabel("Orientation:");
		generalPanel.add(rot,con);
		con.gridy = 7;
		JLabel rotXL = new JLabel("Rotation X:");
		generalPanel.add(rotXL,con);
		final JTextField rotXF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		rotXF.setText(Float.toString(viewObj.getOrientationX()));
		generalPanel.add(rotXF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		con.weightx = 0;
		con.gridy = 8;
		con.gridx = 0;
		JLabel rotYL = new JLabel("Rotation Y:");
		generalPanel.add(rotYL,con);
		final JTextField rotYF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		rotYF.setText(Float.toString(viewObj.getOrientationY()));
		generalPanel.add(rotYF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		con.weightx = 0;
		con.gridy = 9;
		con.gridx = 0;
		JLabel rotZL = new JLabel("Rotation Z:");
		generalPanel.add(rotZL,con);
		final JTextField rotZF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		rotZF.setText(Float.toString(viewObj.getOrientationZ()));
		generalPanel.add(rotZF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		con.weightx = 0;
		con.gridy = 10;
		con.gridx = 0;
		JLabel angleL = new JLabel("Angle:");
		generalPanel.add(angleL,con);
		final JTextField angleF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		angleF.setText(Float.toString(viewObj.getAngle()));
		generalPanel.add(angleF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		con.gridy = 11;
		con.weightx = 0;
		con.gridx = 0;
		generalPanel.add(new JLabel(),con);
		con.gridy = 12;
		JLabel other = new JLabel("Other properties:");
		generalPanel.add(other,con);
		con.gridy = 13;
		JLabel FOVL = new JLabel("Field of View:");
		generalPanel.add(FOVL,con);
		final JTextField FOVF = new JTextField(); 
		con.gridx = 1;
		con.weightx = 0;
		FOVF.setText(Float.toString(viewObj.getFOV()));
		generalPanel.add(FOVF,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		con.gridy = 14;
		con.weightx = 0;
		con.gridx = 0;
		JLabel jumpL = new JLabel("jump:");
		generalPanel.add(jumpL,con);
		final JRadioButton jumpF  = new JRadioButton(); 
		con.gridx = 1;
		con.weightx = 0;
		jumpF.setText("true");
		generalPanel.add(jumpF,con);
		final JRadioButton jumpN  = new JRadioButton(); 
		con.gridx = 2;
		con.weightx = 0;
		jumpN.setText("false");
		if (!viewObj.isJumpTrue()){
			jumpN.setSelected(true);
		}else{
			jumpF.setSelected(true);
		}
		generalPanel.add(jumpN,con);
		
		con.gridx = 3;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		ButtonGroup group = new ButtonGroup();
		group.add(jumpF);
		group.add(jumpN);
		
		con.gridy = 15;
		con.weightx = 0;
		con.gridx = 0;
		JLabel setL = new JLabel("set");
		generalPanel.add(setL,con);
		final JRadioButton setT  = new JRadioButton(); 
		con.gridx = 1;
		con.weightx = 0;
		setT.setText("true");
		generalPanel.add(setT,con);
		final JRadioButton setF  = new JRadioButton(); 
		con.gridx = 2;
		con.weightx = 0;
		setF.setText("false");
		if (!viewObj.isUsed()){
			setF.setSelected(true);
		}else{
			setT.setSelected(true);
		}
		generalPanel.add(setF,con);
		
		con.gridx = 3;
		con.weightx = 1;
		generalPanel.add(new JLabel(""),con);
		
		ButtonGroup setGroup = new ButtonGroup();
		setGroup.add(setT);
		setGroup.add(setF);
		
		
		// Prazny element na vyplnenie spodku
		con.gridy = 16;
		con.gridx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		generalPanel.add(new JLabel(),con);
		
		tabs.addTab("General", scrollPaneForGeneral);
	
		
		JPanel aprovePanel = new JPanel();
		JButton applyBut = new JButton("Apply");
		aprovePanel.setLayout(new BorderLayout());
		aprovePanel.add(applyBut,BorderLayout.EAST);
		aprovePanel.setPreferredSize(new Dimension(400,25));
		
		applyBut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					boolean sameViewpoint=false;
					boolean defaultViewpoint = false;
					viewObj.setPositionX(Float.valueOf(transXF.getText()));
					viewObj.setPositionY(Float.valueOf(transYF.getText()));
					viewObj.setPositionZ(Float.valueOf(transZF.getText()));
					viewObj.setOrientationX(Float.valueOf(rotXF.getText()));
					viewObj.setOrientationY(Float.valueOf(rotYF.getText()));
					viewObj.setOrientationZ(Float.valueOf(rotZF.getText()));
					viewObj.setAngle(Float.valueOf(angleF.getText()));
					viewObj.setJump(jumpF.isSelected());
					ArrayList <VrmlViewPoint> viewpoints=_window.viewpointStorage.getViewpoints();
					_window.listener.viewpoints=viewpoints;
					for (VrmlViewPoint viewpoint : viewpoints) {
						if (viewpoint.equals(viewObj)){
							if( (viewObj.isUsed()) && (setT.isSelected()) ){
								sameViewpoint=true;	
							}
							if( (viewObj.isUsed()) && (!setT.isSelected()) ){
								defaultViewpoint=true;
							}
						}
						if (setT.isSelected()){
							viewpoint.setUsed(false);
						}
					}
					viewObj.setUsed(setT.isSelected());
					if(setT.isSelected() && !sameViewpoint || defaultViewpoint){
						_window.listener.setRotateXAngle(0);
						_window.listener.setRotateYAngle(0);
						_window.listener.setRotateZAngle(0);
						_window.listener.setxMove(0);
						_window.listener.setyMove(0);
						_window.listener.setzMove(0);
						
						//TODO upravit joglEventListener.
					}
					vrmlModel.setModelChanged();
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
			
		this.add(tabs,BorderLayout.CENTER);
		this.add(aprovePanel,BorderLayout.SOUTH);	
	}
	
	public void ShowPropertiesForBackground(){
		final VrmlBackground backgroundObj = (VrmlBackground)object;
		JTabbedPane tabs = new JTabbedPane();
		JPanel generalPanel = new JPanel();
		generalPanel.setLayout(new GridBagLayout());
		JScrollPane scrollPaneForGeneral = new JScrollPane(generalPanel);
		scrollPaneForGeneral.setBorder(null);
		GridBagConstraints con = new GridBagConstraints();
		con.gridx = 0;
		con.gridy = 0;
		con.weighty = 0;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.weightx = 0;
		JLabel objectType = new JLabel("Type:");
		generalPanel.add(objectType,con);
		con.gridx = 1;
		con.weightx = 0;
		JLabel objectName = new JLabel(backgroundObj.getObjectType());
		generalPanel.add(objectName,con);
		con.gridx = 2;
		con.weightx = 1;
		generalPanel.add(new JLabel(),con);
		
		con.weightx = 0;
		con.weighty = 0;
		con.gridwidth = 2;
		con.anchor = GridBagConstraints.LINE_START;
		con.fill = GridBagConstraints.HORIZONTAL;
		con.insets = new Insets(10,10,0,10);
		con.gridy = 1;
		con.gridx = 0;
		
		//Translations
		JLabel trans = new JLabel("Add colors in angle(A:) ascending order:");
		generalPanel.add(trans,con);
		con.gridy = 2;
		con.gridx = 0;
		con.weightx = 0;
		con.gridwidth = 2;
		final JList colorList = new JList(backgroundObj.getSkyColorsAsList()); //data has type Object[]
		colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		colorList.setLayoutOrientation(JList.VERTICAL);
		colorList.setVisibleRowCount(-1);
		JScrollPane listScroller = new JScrollPane(colorList);
		listScroller.setPreferredSize(new Dimension(250, 80));
		generalPanel.add(listScroller,con);
		
		con.gridy = 3;
		con.gridx = 0;
		con.gridwidth = 1;
		JButton addButton = new JButton("Add");
		addButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ev) {
				try{
					Color color = Color.BLACK;
					color= JColorChooser.showDialog( (JButton)ev.getSource(),"Choose Background Color",color);
					String input = JOptionPane.showInputDialog("Enter angle from interval <0, 3.14>:");
					float angle = Float.valueOf(input);
					while (angle<0 || angle>3.14){
						JOptionPane.showMessageDialog(null, "Insterted number is not from interval <0, 3.14>", "Error", JOptionPane.ERROR_MESSAGE);
						 input = JOptionPane.showInputDialog("Enter angle interval <0, 3.14>:");
						 angle = Float.valueOf(input);
					}
					float[] compArray = new float[3];
					SkyColor skyColor = new SkyColor(color.getColorComponents(compArray),angle);
					((DefaultListModel)colorList.getModel()).addElement(skyColor);
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
		generalPanel.add(addButton,con);
		con.gridx = 1;
		con.fill = GridBagConstraints.NONE;
		con.anchor = GridBagConstraints.LINE_END;
		JButton removeButton = new JButton("Remove");
		removeButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					int index = colorList.getSelectedIndex();
					if (index == -1) return;
					DefaultListModel listModel = (DefaultListModel)colorList.getModel();
					listModel.remove(index);
				}catch(Exception e){
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
		generalPanel.add(removeButton,con);
		
		// Prazdny element vyplnenie spodku
		con.gridy = 4;
		con.gridx = 0;
		con.gridwidth = 3;
		con.weighty = 2;
		con.fill = GridBagConstraints.VERTICAL;
		generalPanel.add(new JLabel(),con);
		
		tabs.addTab("General", scrollPaneForGeneral);
	
		
		JPanel aprovePanel = new JPanel();
		JButton applyBut = new JButton("Apply");
		aprovePanel.setLayout(new BorderLayout());
		aprovePanel.add(applyBut,BorderLayout.EAST);
		aprovePanel.setPreferredSize(new Dimension(400,25));
		
		applyBut.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					backgroundObj.loadColorsFromList((DefaultListModel)colorList.getModel());
					vrmlModel.addBackgroundAsComponent();
				}catch(Exception e){
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "Wrong values inserted!", "Error", JOptionPane.ERROR_MESSAGE);
					return;
				}
			}
		});
			
		this.add(tabs,BorderLayout.CENTER);
		this.add(aprovePanel,BorderLayout.SOUTH);	
	}
	
	
	class ColorPickerListener implements ActionListener{
		Color color;
		JLabel previewLabel;
		public ColorPickerListener(Color c,JLabel preview){
			color = c;
			previewLabel = preview;
		}
		
		public void actionPerformed(ActionEvent e) {
			color = JColorChooser.showDialog( (JButton)e.getSource(),"Choose Background Color",color);
			previewLabel.setBackground(color);
		}
		
	}
	
	public byte[] convertStringArraytoByteArray(String[] sarray) throws Exception {
			if (sarray != null) {
			byte bytearray[] = new byte[sarray.length];
			for (int i = 0; i < sarray.length; i++) {
				bytearray[i] =  Byte.parseByte(sarray[i]);
			}
			return bytearray;
			}
			return null;
	}

}
